<template>
	<div class="add-node-btn-box">
		<div class="add-node-btn">
			<el-popover placement="right-start" :width="270" trigger="click" :hide-after="0" :show-after="0">
				<template #reference>
					<el-button type="primary" icon="el-icon-plus" circle></el-button>
				</template>
				<div class="add-node-popover-body">
					<ul>
						<li>
							<el-icon style="color: #ff943e;" @click="addType(1)"><el-icon-user-filled /></el-icon>
							<p>审批节点</p>
						</li>
						<li>
							<el-icon style="color: #ff943e;" @click="addType(2)"><el-icon-user-filled /></el-icon>
							<p>办理节点</p>
						</li>
						<li>
							<el-icon style="color: #3296fa;" @click="addType(3)"><el-icon-promotion /></el-icon>
							<p>抄送节点</p>
						</li>
						<li>
							<el-icon style="color: #15BC83;" @click="addType(5)"><el-icon-share /></el-icon>
							<p>条件分支</p>
						</li>
						<li>
							<el-icon style="color: #15BC83;" @click="addType(7)"><el-icon-share /></el-icon>
							<p>包容分支</p>
						</li>
						<li>
							<el-icon style="color: #15BC83;" @click="addType(9)"><el-icon-share /></el-icon>
							<p>并行分支</p>
						</li>
						<li>
							<el-icon style="color: #15BC83;" @click="addType(10)"><el-icon-share /></el-icon>
							<p>子流程</p>
						</li>
						<li>
							<el-icon style="color: #15BC83;" @click="addType(11)"><el-icon-share /></el-icon>
							<p>ai大模型</p>
						</li>
						<li>
							<el-icon style="color: #15BC83;" @click="addType(11)"><el-icon-share /></el-icon>
							<p>第三方组件</p>
						</li>
					</ul>
				</div>
			</el-popover>
		</div>
	</div>
</template>

<script setup name="addnode">
	import {
		onMounted
	} from 'vue'

	const props = defineProps({
		modelValue: {
			type: Object,
			default: () => ({})
		}
	})

	const emit = defineEmits(['update:modelValue'])

	const getNodeKey = () => 'flk' + Date.now()

	const addType = (type) => {
		let node = {}

		if (type === 1) {
			node = {
				nodeName: "审核人",
				nodeKey: getNodeKey(),
				type: 1,
				setType: 1,
				nodeAssigneeList: [],
				examineLevel: 1,
				directorLevel: 1,
				selectMode: 1,
				termAuto: false,
				term: 0,
				termMode: 1,
				examineMode: 1,
				directorMode: 0,
				childNode: props.modelValue
			}
		} else if (type === 2) {
			node = {
				nodeName: "办理人",
				nodeKey: getNodeKey(),
				type: 2,
				userSelectFlag: true,
				nodeAssigneeList: [],
				childNode: props.modelValue
			}
		} else if (type === 3) {
			node = {
				nodeName: "抄送人",
				nodeKey: getNodeKey(),
				type: 3,
				userSelectFlag: true,
				nodeAssigneeList: [],
				childNode: props.modelValue
			}
		} else if (type === 5) {
			node = {
				nodeName: "条件路由",
				nodeKey: getNodeKey(),
				type: 5,
				conditionNodes: [{
						nodeName: "条件1",
						nodeKey: getNodeKey(),
						type: 4,
						priorityLevel: 1,
						conditionMode: 1,
						conditionList: []
					},
					{
						nodeName: "条件2",
						nodeKey: getNodeKey(),
						type: 4,
						priorityLevel: 2,
						conditionMode: 1,
						conditionList: []
					}
				],
				childNode: props.modelValue
			}
		} else if (type === 7) {
			node = {
				nodeName: "包容路由",
				nodeKey: getNodeKey(),
				type: 7,
				conditionNodes: [{
						nodeName: "包容条件1",
						nodeKey: getNodeKey(),
						type: 6,
						priorityLevel: 1,
						conditionMode: 1,
						conditionList: []
					},
					{
						nodeName: "包容条件2",
						nodeKey: getNodeKey(),
						type: 6,
						priorityLevel: 2,
						conditionMode: 1,
						conditionList: []
					}
				],
				childNode: props.modelValue
			}
		} else if (type === 9) {
			node = {
				nodeName: "并行路由",
				nodeKey: getNodeKey(),
				type: 9,
				conditionNodes: [{
						nodeName: "并行条件1",
						nodeKey: getNodeKey(),
						type: 8,
						priorityLevel: 1,
						conditionMode: 1,
						conditionList: []
					},
					{
						nodeName: "并行条件2",
						nodeKey: getNodeKey(),
						type: 8,
						priorityLevel: 2,
						conditionMode: 1,
						conditionList: []
					}
				],
				childNode: props.modelValue
			}
		} else if (type === 10) {
			node = {
				nodeName: "子流程",
				nodeKey: getNodeKey(),
				type: 10,
				userSelectFlag: true,
				nodeAssigneeList: [],
				childNode: props.modelValue
			}
		} else if (type === 11) {
			node = {
				nodeName: "ai大模型",
				nodeKey: getNodeKey(),
				type: 11,
				userSelectFlag: true,
				nodeAssigneeList: [],
				childNode: props.modelValue
			}
		}

		emit("update:modelValue", node)
	}

	// 如果需要暴露方法给模板或父组件
	defineExpose({
		addType
	})

	onMounted(() => {
		// 初始化逻辑
	})
</script>

<style>
</style>